package com.cs.auth.application.controller;

import com.cs.auth.common.bos.AuthCaptchaBO;
import com.cs.auth.common.entity.BaseResponse;
import com.cs.auth.common.entity.ErrorCode;
import com.cs.auth.common.utlis.ResultUtils;
import com.cs.auth.common.utlis.ThrowUtils;
import com.cs.auth.domain.service.AuthCaptchaDomainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/auth/captcha")
public class AuthCaptchaController {

    @Resource
    private AuthCaptchaDomainService authCaptchaDomainService;

    /**
     * 获取验证码
     * @return
     */
    @GetMapping("/getCaptcha")
    public BaseResponse<AuthCaptchaBO> getCaptcha(){
        //调用domain层方法
        return ResultUtils.success(authCaptchaDomainService.getCaptcha());
    }

    /**
     * 校验验证码
     */
    @GetMapping("/checkCaptcha")
    public BaseResponse<Boolean> checkCaptcha(String code, String uuid){
        //参数校验
        ThrowUtils.throwIf(StringUtils.isAnyBlank(code, uuid), ErrorCode.PARAMS_ERROR);
        //调用domain层方法
        return ResultUtils.success(authCaptchaDomainService.checkCaptcha(code, uuid));
    }

}
